package com.haiheng.voiceandbook.adapter

import android.graphics.Bitmap
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.haiheng.bookmusic.utils.GlideUtils
import com.haiheng.voiceandbook.Constants
import com.haiheng.voiceandbook.Constants.Companion.AlbumPage_URL
import com.haiheng.voiceandbook.R
import com.haiheng.voiceandbook.utils.DisplayUtil
import com.haiheng.voiceandbook.utils.ZXingUtils
import com.ximalaya.ting.android.opensdk.model.album.Album


class VoiceFindAdapter(layoutResId: Int, data: List<Album>?) :
        BaseQuickAdapter<Album, BaseViewHolder>(layoutResId, data) {
    private val TAG = "BookFindAdapter"
    override fun convert(helper: BaseViewHolder?, item: Album?) {
        helper?.run {
            setText(R.id.tv_name, item?.albumTitle)
            setText(R.id.tv_author, item?.announcer?.nickname)
            setText(R.id.tv_desc, item?.recommendReason)
            val imageView = getView<ImageView>(R.id.iv_image)
            item?.coverUrlLarge?.let { GlideUtils.load(mContext, it, imageView) }

            val iv_qcode = getView<ImageView>(R.id.iv_qcode)

            val  url ="${AlbumPage_URL}?id=${item?.id}&libraryNo=${Constants.getLibraryCode()}&PhysicalAddress=${Constants.getDevicesId()}"

            val bitmap: Bitmap = ZXingUtils.createQRImage(
                    url,
                    DisplayUtil.dip2px(mContext, 36f),
                    DisplayUtil.dip2px(mContext, 36f)
            )
            iv_qcode.setImageBitmap(bitmap)


        }


    }


}